package com.stylefeng.guns.modular.platform.service.impl;

import com.stylefeng.guns.core.page.PageInfoBT;
import com.stylefeng.guns.core.result.BaseResultVo;
import com.stylefeng.guns.core.result.JsonReturnHelper;
import com.stylefeng.guns.modular.platform.dao.SmallInfoMapper;
import com.stylefeng.guns.modular.platform.model.SmallInfo;
import com.stylefeng.guns.modular.platform.service.ISmallInfoService;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.google.gson.JsonObject;

import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 记录平台小程序信息 服务实现类
 * </p>
 *
 * @author stylefeng123
 * @since 2018-07-24
 */
@Service
public class SmallInfoServiceImpl extends ServiceImpl<SmallInfoMapper, SmallInfo> implements ISmallInfoService {

	private Logger logger = LoggerFactory.getLogger(this.getClass());

	@Resource
	private SmallInfoMapper smallInfoMapper;

	@Override
	public BaseResultVo getList(Page page, SmallInfo smallInfo) {
		logger.error("获取数据接口getList:", JSONObject.toJSON(smallInfo));

		try {
			List<SmallInfo> list = smallInfoMapper.getList(page, smallInfo);
			page.setRecords(list);
		} catch (Exception e) {
			logger.error("获取数据异常!", e);
			return JsonReturnHelper.getFailWithError("获取数据异常!", "000001");
		}
		return JsonReturnHelper.getSuccessWithData(page);
	}

	@Override
	public BaseResultVo getRandomList() {
		logger.error("获取数据接口getRandomList");
		List<SmallInfo> list = null;
		try {
			list = smallInfoMapper.getRandomList();
		} catch (Exception e) {
			logger.error("获取数据异常!", e);
			return JsonReturnHelper.getFailWithError("获取数据异常!", "000001");
		}
		return JsonReturnHelper.getSuccessWithData(list);
	}

	@Override
	public BaseResultVo getHotList() {
		logger.error("获取数据接口getHotList");
		List<SmallInfo> list = null;
		try {
			list = smallInfoMapper.getHotList();
		} catch (Exception e) {
			logger.error("获取数据异常!", e);
			return JsonReturnHelper.getFailWithError("获取数据异常!", "000001");
		}
		return JsonReturnHelper.getSuccessWithData(list);
	}

	@Override
	public BaseResultVo getNewList() {
		logger.error("获取数据接口getNewList");
		List<SmallInfo> list = null;
		try {
			list = smallInfoMapper.getNewList();
		} catch (Exception e) {
			logger.error("获取数据异常!", e);
			return JsonReturnHelper.getFailWithError("获取数据异常!", "000001");
		}
		return JsonReturnHelper.getSuccessWithData(list);
	}
	
	@Override
	public BaseResultVo getTypeList() {
		logger.error("获取数据接口getTypeList");
		List<String> list = null;
		try {
			list = smallInfoMapper.getTypeList();
		} catch (Exception e) {
			logger.error("获取数据异常!", e);
			return JsonReturnHelper.getFailWithError("获取数据异常!", "000001");
		}
		return JsonReturnHelper.getSuccessWithData(list);
	}
	

}
